package org.jeecg.modules.simulator.factory.train.plan;

import org.jeecg.modules.simulator.factory.train.TPathItem;
import org.jeecg.modules.simulator.factory.train.load.TPathRead;
import org.jeecg.modules.simulator.model.train.timeplan.TrainPlanTable;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @program: gp
 * @description:
 * @author:  renzhg
 * @create: 2024-08-07 14:51
 **/
public class TimePlanJsonFactory  implements  TimePlanFactory{
    TPathRead tPathRead = new TPathRead();

    @Getter
    @Setter
    Map<String, List<TrainPlanTable>> trainPlanTableByLineMap = new HashMap<>();

    //时刻表生成
    public void initReadTimeTable(String timepath) {
        List<TPathItem> timetableList = tPathRead.tpathItemRead(timepath);
        List<TrainPlanTable> trainPlanTablelist = new ArrayList<>();
        for (int i = 0; i < timetableList.size(); i++) {
            TrainPlanTable trainPlanTable = new TrainPlanTable();
            TPathItem tPathItem = timetableList.get(i);
            trainPlanTable.setArriveStaionName(tPathItem.getArriveStaionName());
            trainPlanTable.setArriveTime(tPathItem.getArriveTime());
            trainPlanTable.setDepartTime(tPathItem.getDepartTime());
            trainPlanTable.setRemainTime(tPathItem.getRemainTime());
            trainPlanTable.setTrainId(tPathItem.getTrainId());
            trainPlanTable.setTrainNum(tPathItem.getTrainNum());
            trainPlanTable.setIndex(tPathItem.getIndex());
            trainPlanTable.setLineId(tPathItem.getLineId());
            trainPlanTablelist.add(trainPlanTable);
        }

        trainPlanTableByLineMap = trainPlanTablelist.stream().collect(Collectors.groupingBy(o -> o.getLineId()));

//        Map<String, List<TrainPlanTable>> TrainPlanTableMap = trainPlanTablelist.stream().collect(Collectors.groupingBy(o -> o.getTrainId() + "-" + o.getTrainNum()));


//        Map<String, TrainPlanTablePath> trainPlanTablePathMap = new HashMap<>();
//        for (Map.Entry<String, List<TrainPlanTable>> entry : TrainPlanTableMap.entrySet()) {
//            List<TrainPlanTable> trainPlanTables = entry.getValue();
//            TrainPlanTablePath trainPlanTablesPath = new TrainPlanTablePath(trainPlanTables,entry.getKey());
//            trainPlanTablePathMap.put(entry.getKey(), trainPlanTablesPath);
//        }


    }


    public void loadTimePlanData() {

//       String   timepath1 = "D:/aaaa/timetable1.json";
//
//       String   timepath11 = "D:/aaaa/timetable11.json";
//       String   timepath12 = "D:/aaaa/timetable12.json";
//       String   timepath13 = "D:/aaaa/timetable13.json";
//
//       String   timepath14 = "D:/aaaa/timetable14.json";
//
//       String   timepath15 = "D:/aaaa/timetable15.json";
//
//
//       String   timepath2 = "D:/aaaa/timetable2.json";
//
//       String   timepath21 = "D:/aaaa/timetable21.json";
//       String   timepath22 = "D:/aaaa/timetable22.json";
//       String   timepath23 = "D:/aaaa/timetable23.json";
//       String   timepath24 = "D:/aaaa/timetable24.json";
        initReadTimeTable("D:/aaaa/train_schedule.json");
    }
}
